package com.dotndot.view.widget;

import android.app.*;
import android.content.*;
import android.content.DialogInterface.OnKeyListener;
import android.view.*;

import com.dotndot.*;

public class BaseDialog
{
    private static BaseDialog baseDialog = new BaseDialog();

    private BaseDialog()
    {

    }

    public static BaseDialog getIns()
    {
        return baseDialog;
    }

    public void showDialog( Context context, int messageId )
    {
        showDialog(context, null, context.getString(messageId), context.getString(R.string.confirm), null, null, null, null, null);
    }

    public void showDialog( Context context, int messageId, DialogInterface.OnClickListener neutralListener )
    {
        showDialog(context, null, context.getString(messageId), context.getString(R.string.confirm), neutralListener, null, null, null, null);
    }

    public void showDialog( Context context, int titleId, int messageId )
    {
        showDialog(context, context.getString(titleId), context.getString(messageId), context.getString(R.string.confirm), null, null, null, null,
                null);
    }

    // public void showDialog(Context context, int titleId, int messageId,
    // DialogInterface.OnClickListener positiveListener){
    // showDialog(context, context.getString(titleId),
    // context.getString(messageId),
    // context.getString(R.string.ok), positiveListener, null, null, true);
    // }

    public void showDialog( Context context, String title, String message, String neturalText, DialogInterface.OnClickListener neutralListener,
            String positiveText, DialogInterface.OnClickListener positiveListener, String negativeText,
            DialogInterface.OnClickListener negativeListener )
    {

        AlertDialog.Builder alert = new AlertDialog.Builder(context);

        if( title != null )
        {
            alert.setTitle(title);
        }

        if( message != null )
        {
            alert.setMessage(message);
        }

        if( neturalText != null )
        {
            alert.setNeutralButton(neturalText, neutralListener);
        }

        if( positiveText != null )
        {
            alert.setPositiveButton(positiveText, positiveListener);
        }

        if( negativeText != null )
        {
            alert.setNegativeButton(negativeText, negativeListener);
        }

        alert.setOnKeyListener(new OnKeyListener()
        {
            @Override
            public boolean onKey( DialogInterface dialog, int keyCode, KeyEvent event )
            {
                if( keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_MENU )
                {
                    return true;
                }
                return false;
            }
        });

        alert.setCancelable(false);
        alert.show();
    }
}
